package java_class_work.week08.internet.sendStringDemo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Tiam
 * @Date 2022/11/4 21:10
 * @Description: 服务端启动类
 */
public class RunServer {
    public static Map<Socket, String> map = new HashMap<>();

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        try {
            serverSocket = new ServerSocket(8888);
            System.out.println("服务端已启动, 等待连接...");
            int num = 0;
            while (true) {
                socket = serverSocket.accept();
                map.put(socket, null);
                System.out.println(socket+"已连接, "+(++num)+"号用户");
                new Thread(new ServerThread(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
